<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of requirements_controller
 *
 * @author 250-1-405
 */
class RequirementsController extends AppController {

    //put your code here
    var $name = "Requirements";

    function index($call_id) {
        $this->Requirement->recursive = -1;
        $this->set("call_id", $call_id);
        $this->set("requisitos", $this->Requirement->find("all", array("conditions" => array('Requirement.call_id' => $call_id), "fields" => array("Requirement.texto", "Requirement.id", "Requirement.requirement_type_id"), 'order' => array('requirement_type_id' => 'ASC'))));
    }

    function add($call_id) {
        $this->set("call_id", $call_id);
        if (!empty($this->data)) {

            if ($this->Requirement->saveAll($this->data)) {
                $this->Session->setFlash('Requisito adicionado con éxito');
                $this->redirect(array('controller' => 'Requirements', 'action' => 'index', $call_id));
            }
        }
    }

    function edit($id = null) {
        $this->Requirement->recursive = -1;
        if (empty($this->data)) {

            $this->data = $this->Requirement->Find("first", array("conditions" => array("Requirement.id" => $id)));
        } else {
            if ($this->Requirement->saveAll($this->data)) {
                $this->Session->setFlash("Registro actualizado con Éxito");
                $this->redirect(array('controller' => 'Requirements', 'action' => 'index', $this->data['Requirement']['call_id']));
            } else {
                $this->Session->setFlash("Error ");
            }
        }
    }

}

?>
